<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.w3.org/1999/xhtml">

<head>
    <th:block th:include="common/common_head :: commonHeader('物料主数据')"/>
    <link rel="stylesheet" th:href="@{/static/js/plugins/jquery-layout/jquery.layout-latest.css}">
    <style type="text/css">
        .la{text-align:left;}
        .textBox{text-align:right;}
    </style>
</head>

<body class="gray-bg">

<div class="container-div ui-layout-center">
    <div class="row">
        <div class="col-sm-12 search-condition">
            <form class="form-inline" id="materialForm" th:action="@{/material/list}">
                <div class="select-list">
                    <ul>
                        <li class="col-sm-3">
                            <label>物料号：</label>
                            <input name="materialCode" type="text"/>
                        </li>
                        <li class="col-sm-3">
                            <label>物料描述：</label>
                            <input name="materialDesc" type="text"/>
                        </li>
                        <li class="col-sm-3">
                            <div>
                                <label>创建日期：</label>
                                <input name="creationDate"  id="creationDate" type="text"/>
                            </div>
                        </li>

                        <li class="col-sm-3">
                            <div>
                                <label>创建人员名称：</label>
                                <input name="createdBy" type="text"/>
                            </div>
                        </li>
                        <li class="col-sm-3">
                            <div>
                                <label>物料状态：</label>
                                <input name="materialStatus" type="text"/>
                            </div>
                        </li>

                        <li class="col-sm-3">
                            <div>
                                <label>行业领域：</label>
                                <input name="industrySector" type="text"/>
                            </div>
                        </li>

                        <li class="col-sm-3">
                            <div>
                                <label>物料组：</label>
                                <input name="materialGroup" type="text"/>
                            </div>
                        </li>
                        <li class="col-sm-3">
                            <button class="btn btn-primary btn-rounded btn-sm" id="materialSearchBtn" type="button"><i
                                    class="fa fa-search"></i>&nbsp;搜索
                            </button>
                            <button class="btn btn-warning btn-rounded btn-sm" type="reset"><i class="fa fa-eraser"></i>&nbsp;重置
                            </button>
                            <button class="btn btn-primary btn-rounded btn-sm" id="materialAdvancedSearch"
                                    style="display: none"
                                    type="button"><i class="fa fa-caret-down"></i>&nbsp;高级搜索
                            </button>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="col-sm-12 select-info order-table">
            <div class="btn-group hidden-xs toolbar" id="materialToolBar" role="group">
                <a class="btn btn-outline btn-success btn-rounded" shiro:hasPermission="material:add" onclick="toAddMaterialHeader()">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-outline btn-success btn-rounded" onclick="toEditMaterialHeader()">
                    <i class="fa fa-edit"></i> 编辑
                </a>
                <a class="btn btn-outline btn-danger btn-rounded" onclick="deleteMaterialHeader()">
                    <i class="fa fa-edit"></i> 删除
                </a>
            </div>
            <table id="material" data-mobile-responsive="true">

            </table>
        </div>
    </div>
</div>
<!-- 引入公共js -->
<div th:include="common/onload_js :: onloadJS"></div>
<script th:src="@{/static/js/plugins/jquery-layout/jquery.layout-latest.js}" type="text/javascript"></script>

<!-- Page-Level Scripts -->
<script type="text/javascript">

    //面向对象
    var searcherBS = Searcher.createBS('#material',
        [
            {checkbox: true},
            {title: '物料号', field: 'materialCode'},
            {title: '物料描述', field: 'materialDesc'},
            {title: '创建日期', field: 'creationDate'},
            {title: '创建对象的人员名称', field: 'createdBy'},
            {title: '上次更改的日期', field: 'lastUpdateDate'},
            {title: '对象更改人员的名称', field: 'lastUpdatedBy'},
            {title: '维护全部物料状态', field: 'materialStatus'},
            {title: '物料类型', field: 'materialType'},
            {title: '行业领域', field: 'industrySector'},
            {title: '物料组', field: 'materialGroup'},
            {title: '普通项目类别组', field: 'normalItemCategory'},
            {title: '旧物料号', field: 'oldMaterialCode'},
            {title: '基本计量单位', field: 'basicUnit'},
            {title:"备注",field:"remark"}
        ]
    );

    //刷新数据
    function refresh() {
        searcherBS.refresh();
    }

    // 初始化时间插件
    laydate.render({elem: '#effectiveDate'});
    laydate.render({elem: '#deletedDate'});
    laydate.render({elem: '#creationDate'});

    initDictDataSel();//初始化所有字典数据

    /**
     * @Description: 新增物料
     */
    function toAddMaterialHeader() {
        var index = Dialog.openUrl("新增物料信息", ctxPath + '/material/toAdd', {
            area: ['900px', '700px'],
            maxmin: true,
            end: function () {
            }
        });
        layer.full(index);
    }

    /**
     * @Description:  编辑按钮跳转功能
     */
    function toEditMaterialHeader() {
        //field:"pkId"
        var rowDatas = searcherBS.getSelectedRows("materialCode");
        var materialCode=rowDatas;
        if (rowDatas.length != 1) {
            Dialog.errorMsg("请选择一行进行编辑");
            return;
        }
        //截取料号首字母
        rowDatas = rowDatas.toString().substring(0, 1);
        //用料号首字母判断是不是新建料号,不是新建料号是没有库存的
        if (rowDatas != "N") {
            Dialog.errorMsg("不是新建料号,无法进行该操作!");
            return;
        }
        var index = Dialog.openUrl("编辑物料信息", ctxPath + '/material/toEdit/' + materialCode,
            {
                area: ['900px', '700px'],
                maxmin: true,
                end: function () {
                }
            });
        layer.full(index)
    }
   /**
    * @Description: 删除物料功能
    */
    function deleteMaterialHeader() {
        var rowDatas = searcherBS.getSelectedRows("materialCode");
        if (rowDatas.length < 1) {
            Dialog.errorMsg("请至少选择一行");
            return;
        }
        Dialog.confirm('确定删除？', function (index) {
            Page.ajaxPOST(ctxPath + "/material/delete", {materialCode: rowDatas}, function () {
                Dialog.msg("操作成功", function () {
                    searcherBS.refresh();
                });
            }, {"loadingMsg" : "正在往服务器提交数据……"});
        });
    }
</script>
</body>
</html>